=begin pod :kind("Type") :subkind("class") :category("basic")

=TITLE class NumStr

=SUBTITLE Dual value floating-point number and string

    class NumStr is Allomorph is Num { }

C<NumStr> is a dual value type, a subclass of both
L«C<Allomorph>|/type/Allomorph», hence L«C<Str>|/type/Str», and
L«C<Num>|/type/Num».

See L«C<Allomorph>|/type/Allomorph» for further details.

=begin code
my $num-str = <42.1e0>;
say $num-str.^name;         # OUTPUT: «NumStr␤»

my Num $num = $num-str;     # OK!
my Str $str = $num-str;     # OK!

# ∈ operator cares about object identity
say 42e10 ∈ <42e10  55  1>; # OUTPUT: «False␤»
=end code

=head1 Methods

=head2 method new

    method new(Num $i, Str $s)

The constructor requires both the C<Num> and the C<Str> value, when constructing one
directly the values can be whatever is required:

    my $f = NumStr.new(42.1e0, "forty two and a bit");
    say +$f; # OUTPUT: «42.1␤»
    say ~$f; # OUTPUT: «"forty two and a bit"␤»

=head2 method Num

    method Num

Returns the C<Num> value of the C<NumStr>.

=head2 method Numeric

Defined as:

    multi method Numeric(NumStr:D: --> Num:D)
    multi method Numeric(NumStr:U: --> Num:D)

The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues
a warning about using an uninitialized value in numeric context and then returns value C<0e0>.

=head2 method Real

Defined as:

    multi method Real(NumStr:D: --> Num:D)
    multi method Real(NumStr:U: --> Num:D)

The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues
a warning about using an uninitialized value in numeric context and then returns value C<0e0>.

=head1 Operators

=head2 infix C«===»

    multi sub infix:<===>(NumStr:D $a, NumStr:D $b)

C<NumStr> Value identity operator. Returns C<True> if the C<Num>
values of C<$a> and C<$b> are L<identical|/routine/===> and their C<Str>
values are also L<identical|/routine/===>. Returns C<False> otherwise.

=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
